package cn.jbit.ams.user.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.jbit.ams.user.biz.UserService;
import cn.jbit.ams.user.dao.UserMapper;
import cn.jbit.ams.user.pojo.Product;
import cn.jbit.ams.user.pojo.User;

@Service
@Transactional
public class UserServiceImpl implements UserService{

	@Autowired
	UserMapper usermapper;

	@Override
	public User login(String username) {
		// TODO Auto-generated method stub
		return usermapper.dologin(username);
	}

	@Override
	public void insert(User user) {
		try {
			usermapper.insert(user);
		} catch (Exception e) {
			System.out.println("注册失败");
		}
	}

	@Override
	public Page<User> findUser(Integer pageNum,String userName) {
		System.out.println(pageNum);
		if(pageNum==null) {
			pageNum=1;
		}
		Page<User> page=PageHelper.startPage(pageNum,3);
		usermapper.findUser(userName);
		return page;
	}

	@Override
	public int countPage() {
		int count=usermapper.count();
		int countPage=count%3==0?count/3:count/3+1;
		return countPage;
	}

	@Override
	public void updateUser(User user) {
		try {
			usermapper.updateUser(user);
		} catch (Exception e) {
			System.out.println("修改失败");
			System.out.println(e);
		}
	}

	@Override
	public User getUser(Integer userId) {
		// TODO Auto-generated method stub
		return usermapper.getUser(userId);
	}

	@Override
	public List<Product> getProduct() {
		// TODO Auto-generated method stub
		return usermapper.getProduct();
	}

	@Override
	public List<User> getAdminUser() {
		// TODO Auto-generated method stub
		return usermapper.getAdminUser();
	}

	

}
